<template>
	<!--新增对话框-->
	<el-dialog
		:title="editForm.id ? '编辑' : '新增'"
		:visible.sync="dialogVisible"
		width="800px"
		:before-close="handleClose"
	>
		<el-form :model="editForm" :rules="editFormRules" ref="editForm">
			<el-form-item label="报告时间" prop="date" label-width="160px">
        <el-date-picker
          v-model="editForm.date"
          type="month"
          value-format="yyyy.MM"
          disabled
          placeholder="选择年月">
        </el-date-picker>
			</el-form-item>
      <el-row>
        <el-col :span="12">
          <el-form-item label="综合运费均值" prop="comprehensive" label-width="160px">
            <el-input-number v-model="editForm.comprehensive" :precision="2" :step="1" :min="0"></el-input-number>
          </el-form-item>
          <el-form-item label="油船运费均值" prop="oiltanker" label-width="160px">
            <el-input-number v-model="editForm.oiltanker" :precision="2" :step="1" :min="0"></el-input-number>
          </el-form-item>
          <el-form-item label="散货船运费均值" prop="bulk" label-width="160px">
            <el-input-number v-model="editForm.bulk" :precision="2" :step="1" :min="0"></el-input-number>
          </el-form-item>
          <el-form-item label="箱船运费均值" prop="container" label-width="160px">
            <el-input-number v-model="editForm.container" :precision="2" :step="1" :min="0"></el-input-number>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="大型LNG运输船运费均值" prop="seventeenpointfourlpg" label-width="180px">
            <el-input-number v-model="editForm.seventeenpointfourlpg" :precision="2" :step="1" :min="0"></el-input-number>
          </el-form-item>
          <el-form-item label="LPG运输船运费均值" prop="lpg" label-width="180px">
            <el-input-number v-model="editForm.lpg" :precision="2" :step="1" :min="0"></el-input-number>
          </el-form-item>
          <el-form-item label="大型汽车运输船运费均值" prop="carcarrier" label-width="180px">
            <el-input-number v-model="editForm.carcarrier" :precision="2" :step="1" :min="0"></el-input-number>
          </el-form-item>
        </el-col>
      </el-row>
		</el-form>
		<div slot="footer" class="dialog-footer">
			<el-button @click="resetForm('editForm')">取 消</el-button>
			<el-button type="primary" @click="submitForm('editForm')">确 定</el-button>
		</div>
	</el-dialog>
</template>

<script>
import { isNumber } from '@/utils/validate';
import { formatServerDate, dateFormatStr } from '@/utils/date';
export default {
	name: 'AddUpdateFreightRete',
	components: {},
	props: {
		type: {
			type: String,
			default: '1',
		}
	},
	data() {
		return {
			editForm: {},
			loading: false,
			dialogVisible: false,
			editFormRules: {
				date: [{ required: true, message: '请选择报告年月', trigger: 'blur' }],
				comprehensive: [{ required: true, message: '请输入综合运费均值', trigger: 'blur' }],
        oiltanker: [{ required: true, message: '请输入油船运费均值', trigger: 'blur' }],
        bulk: [{ required: true, message: '请输入散货船运费均值', trigger: 'blur' }],
        container: [{ required: true, message: '请输入箱船运费均值', trigger: 'blur' }],
        seventeenpointfourlpg: [{ required: true, message: '请输入大型LNG运输船运费均值', trigger: 'blur' }],
        lpg: [{ required: true, message: '请输入LPG运输船运费均值', trigger: 'blur' }],
        carcarrier: [{ required: true, message: '请输入大型汽车运输船运费均值', trigger: 'blur' }],
			},
		};
	},
	mounted() {
		// this.getFarmList('');
	},

	methods: {
		resetForm(formName) {
			this.$refs[formName].resetFields();
			this.dialogVisible = false;
			this.editForm = {};
		},
		handleClose() {
			this.resetForm('editForm');
		},
		submitForm(formName) {
			this.$refs[formName].validate((valid) => {
				if (valid) {
          const { date,...rest} = this.editForm;
					this.$axios.get('/admin/boat/ship/freightrate/' + (this.editForm.id ? 'edit' : 'edit'), {params: {...rest},})
            .then((res) => {
              this.$message({
                showClose: true,
                message: '恭喜你，操作成功',
                type: 'success',
                onClose: () => {
                  this.$emit('refreshDataList');
                },
              });
            this.dialogVisible = false;
            this.resetForm(formName);
          });
        } else {
          console.log('error submit!!');
          return false;
        }
			}).catch((err) => {
        console.log(err);
      });
		},
		checkIsDisabledDate(date){
			console.log(date);
			return true;
		},
		init(id) {
			this.dialogVisible = true;
			if (id != null && id != '' && id > 0) {
				this.$axios.get('/admin/boat/ship/freightrate/detail?id=' + id).then((res) => {
          const {result = {}} = res;
          const { ...rest} = result;
          this.editForm = {
              id: id,
              date: formatServerDate(rest.date, dateFormatStr),
              bulk: rest.bulk,
              container: rest.container,
              comprehensive: rest.comprehensive,
              lpg: rest.lpg,
              oiltanker: rest.oiltanker,
              seventeenpointfourlpg: rest.seventeenpointfourlpg,
              carcarrier: rest.carcarrier,
          };
				});
			}
		},
	},
};
</script>

<style scoped>
.avatar-uploader .el-upload {
	border: 1px dashed #d9d9d9;
	border-radius: 6px;
	cursor: pointer;
	position: relative;
	overflow: hidden;
}
.avatar-uploader .el-upload:hover {
	border-color: #409eff;
}
.avatar-uploader-icon {
	font-size: 28px;
	color: #8c939d;
	width: 178px;
	height: 178px;
	line-height: 178px;
	text-align: center;
}
.avatar {
	width: 178px;
	height: 178px;
	display: block;
}
</style>
